package com.foxhorse.androidpractice.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.GridView;

import com.foxhorse.androidpractice.R;
import com.foxhorse.androidpractice.activity.customizeview.CustomizeDrawView1Activity;
import com.foxhorse.androidpractice.activity.customizeview.CustomizeDrawView2Activity;
import com.foxhorse.androidpractice.activity.kotlin.listview.KotlinListViewActivity;
import com.foxhorse.androidpractice.activity.webview.CameraWebViewActivity;
import com.foxhorse.androidpractice.adapter.MainMenuAdapter;
import com.foxhorse.androidpractice.entity.MainMenu;
import com.foxhorse.androidpractice.utils.Constant;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    private final static String TAG = "MainActivity";
    private GridView gridView;
    private List<MainMenu> list;
    private MainMenuAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = (GridView) findViewById(R.id.gridview);
        list = new ArrayList<>();
        String[] mainMenus = getResources().getStringArray(R.array.main_menu);
        for (int i = 0; i < mainMenus.length; i++) {
            list.add(new MainMenu(mainMenus[i].substring(0, mainMenus[i].indexOf("|")), mainMenus[i].substring(mainMenus[i].indexOf("|") + 1)));
        }
        adapter = new MainMenuAdapter(context, list);
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener((parent, view, position, id) -> {
            switch (list.get(position).getTag()) {
                case Constant.CAMERA_WEBVIEW_ACTIVITY:
                    startActivity(new Intent(context, CameraWebViewActivity.class));
                    break;
                case Constant.KOTLIN_LISTVIEW_ACTIVITY:
                    startActivity(new Intent(context, KotlinListViewActivity.class));
                    break;
                case Constant.CUSTOMIZE_VIEW_1:
                    startActivity(new Intent(context, CustomizeDrawView1Activity.class));
                    break;
                case Constant.CUSTOMIZE_VIEW_2:
                    startActivity(new Intent(context, CustomizeDrawView2Activity.class));
                    break;
                default:
                    break;
            }
        });
    }
}
